package com.example.springgobang.model;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    // 往数据库中插入一个用户,用于注册功能
    @Insert("insert into user values (null, #{username}, #{password}, 1000, 0, 0)")
    void insert(User user);

    // 根据用户名,来查询用户的详细信息,用于登录功能
    @Select("select * from user where username = #{username}")
    User selectByName(String username);

    // 总比赛场数 + 1, 获胜场数 + 1, 天梯分数 + 50
    @Update("update user set totalCount = totalCount + 1, winCount = winCount + 1," +
            " score = score + 50 where userId = #{userId}")
    void userWin(int userId);

    // 总比赛场数 + 1, 获胜场数不变, 天梯分数 - 50
    @Update("update user set totalCount = totalCount + 1, score = score - 50" +
            " where userId = #{userId}")
    void userLose(int userId);
}
